package jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

public class Test {
    public static void main(String[] args) {
        try(Connection connection = DBUtil.getConnection();){
            connection.setAutoCommit(false);
            String sql = "UPDATE teacher "+
            "SET salary=salary+500 " +
            "WHERE subject_id=(SELECT id FROM subject WHERE name ='语文'）";
            Statement  statement = connection.createStatement();
            int num = statement.executeUpdate(sql);
            System.out.println(num>0?"涨工资成功":"涨工资失败");

            connection.commit();
            System.out.println("提交成功");
            connection.rollback();
            System.out.println("回滚成功");

        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
